function numIslands(grid){
    let m =  grid.length
    let n = grid[0].length
    let count = 0
    for(let i=0; i<m; i++){
        for(let j=0; j<n; j++){
            if(grid[i][j] == 1){
                count += 1
                loopIsEqual1(i, j)
            }
        }
    }


    function loopIsEqual1(ii, jj){
        if(ii<m && jj<n && ii>=0 && jj>=0 && grid[ii][jj] == 1){
             // 前后左右递归遍历，遍历完回溯的时候将值置为0
            loopIsEqual1(ii+1, jj)
            grid[ii][jj] = 0
            loopIsEqual1(ii-1, jj)
            grid[ii][jj] = 0
            loopIsEqual1(ii, jj+1)
            grid[ii][jj] = 0
            loopIsEqual1(ii, jj-1)
            grid[ii][jj] = 0
        }
    }
}



let grid = [
    ["1","1","0","0","0"],
    ["1","1","0","0","0"],
    ["0","0","1","0","0"],
    ["0","0","0","1","1"]
  ]
  

  
numIslands(grid)